-
Notifications
You must be signed in to change notification settings - Fork 0
Conversation
…to control cell color based on date of last update
…variable to make more specific and clear.
…f items last update.
Closes #90 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logically this works well. Formatting needs some work.
return ( | ||
<TableCell | ||
classes={classes} | ||
{...reactTableCellProps} //expands table cell props to allow access to style props |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move comment above line of code it applies to. Use a space between //
and the start of the comment. Use proper sentence case with comments.
{...reactTableCellProps} //expands table cell props to allow access to style props | |
// Expands table cell props to allow access to style props. | |
{...reactTableCellProps} |
<TableCell | ||
classes={classes} | ||
{...reactTableCellProps} //expands table cell props to allow access to style props | ||
style={{ ...reactTableCellProps.style, backgroundColor: backgroundColor }} //expands style prop of table cell to allow addtion of custom styling without losing default styling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move comment above line of code it applies to. Use a space between //
and the start of the comment. Use proper sentence case with comments.
style={{ ...reactTableCellProps.style, backgroundColor: backgroundColor }} //expands style prop of table cell to allow addtion of custom styling without losing default styling | |
// Expands style prop of table cell to allow addition of custom styling without losing default styling. | |
style={{ ...reactTableCellProps.style, backgroundColor: backgroundColor }} |
@@ -34,7 +65,8 @@ export default function ItemTable({ data }) { | |||
borderLeftWidth: "1px", | |||
borderLeftStyle: "solid", | |||
borderColor: theme.palette.type === "light" ? theme.palette.grey[300] : theme.palette.grey[500] | |||
} | |||
}, | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary blank line.
@@ -48,7 +80,7 @@ export default function ItemTable({ data }) { | |||
{ Header: 'Subject', accessor: 'subject' }, | |||
{ Header: 'Status', accessor: 'status', }, | |||
{ Header: 'Priority', accessor: 'priority' }, | |||
{ Header: 'Last Updated', accessor: 'lastUpdated', Cell: ({ value }) => <RelativeTime value={value} /> }, | |||
{ Header: 'Last Updated', accessor: 'lastUpdated', Cell: ({ value }) => <LastUpdatedCell time={value} /> }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove Cell overrides because we're controlling them in the render statements below. The definitions here will never be used.
<Table {...getTableProps} | ||
aria-label="Table of Queue Items" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When splitting component props across multiple lines, do not include props on the same line as the opening tag.
<Table {...getTableProps} | |
aria-label="Table of Queue Items" | |
<Table | |
{...getTableProps} | |
aria-label="Table of Queue Items" |
@@ -135,9 +170,24 @@ export default function ItemTable({ data }) { | |||
selected={isSelected} | |||
{...row.getRowProps()} > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like with starting tags and multi-line props, place tag endings on their own line.
{...row.getRowProps()} > | |
{...row.getRowProps()} | |
> |
</TableCell> | ||
|
||
cell.render( | ||
//conditonally renders custom cell component based on cell.column.id prop value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a space between // and the start of the comment. Use proper sentence case with comments.
//conditonally renders custom cell component based on cell.column.id prop value | |
// Conditonally renders custom cell component based on cell.column.id prop value. |
cell.column.id === "lastUpdated" | ||
? <LastUpdatedCell | ||
time={cell.value} | ||
reactTableCellProps={cell.getCellProps()} | ||
classes={{ root: classes.columnBorders }} | ||
/> | ||
: | ||
<TableCell | ||
{...cell.getCellProps()} | ||
classes={{ root: classes.columnBorders }} | ||
> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using multi line values for ternary operators, wrap the value for true and false in parenthesis.
cell.column.id === "lastUpdated" | |
? <LastUpdatedCell | |
time={cell.value} | |
reactTableCellProps={cell.getCellProps()} | |
classes={{ root: classes.columnBorders }} | |
/> | |
: | |
<TableCell | |
{...cell.getCellProps()} | |
classes={{ root: classes.columnBorders }} | |
> | |
cell.column.id === "lastUpdated" | |
? ( | |
<LastUpdatedCell | |
time={cell.value} | |
reactTableCellProps={cell.getCellProps()} | |
classes={{ root: classes.columnBorders }} | |
/> | |
) | |
: ( | |
<TableCell | |
{...cell.getCellProps()} | |
classes={{ root: classes.columnBorders }} | |
> | |
) |
{cell.value} | ||
</TableCell> | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra blank line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic looks good. Needs refactoring.
const LastUpdatedCell = ({ time, reactTableCellProps, classes }) => { | ||
const lastUpdated = new Date(time).getTime(); | ||
const now = new Date().getTime(); | ||
const timeDelta = now - lastUpdated; | ||
const day = 24 * 60 * 60 * 1000; | ||
const week = day * 7; | ||
const month = week * 4; | ||
|
||
let backgroundColor = "white"; | ||
if (timeDelta > day && timeDelta <= week) { | ||
backgroundColor = red[100] | ||
} | ||
else if (timeDelta > week && timeDelta <= month) { | ||
backgroundColor = red[300] | ||
} | ||
else if (timeDelta > month) { | ||
backgroundColor = red[500] | ||
} | ||
|
||
return ( | ||
<TableCell | ||
classes={classes} | ||
// Expands table cell props to allow access to style props. | ||
{...reactTableCellProps} | ||
// Expands style prop of table cell to allow addtion of custom styling without losing default styling. | ||
style={{ ...reactTableCellProps.style, backgroundColor: backgroundColor }} | ||
> | ||
<RelativeTime value={time} /> | ||
</TableCell> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic is good. This should be its own component with docs. It should also extend an ItemTableCell (see comments below about ItemTableCell.)
<TableCell | ||
{...cell.getCellProps()} | ||
classes={{ root: classes.columnBorders }} | ||
> | ||
{cell.value} | ||
</TableCell> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to avoid WET (writing everything twice) code and keep it DRY (don't repeat yourself). We can do that here by making a component for a TableCell and giving it the CSS override equivalent to classes.columnBorders
. It could be called something like ItemTableCell. Then we'd have one and only one place where we need to make styling changes.
Something like this could also be extended by the LastUpdatedCell so we're not duplicating logic.
A significant amount of work needed to be put in to resolve some logical, visual, and organizational issues. LogicalWith more than 2 options, ternary statements must be nested and this is difficult to read. The LastUpdatedCell had styling logic from the ItemTableCell duplicated unnecessarily which would lead to breaking changes in the future. The LastUpdatedCell is not effectively inheriting from the LastUpdatedCell to avoid this issue. The logic in the LastUpdatedCell that determines the background color was moved to its own function to better isolate code fragments. This also made it easier to inset the background color into the styling info from React Table. VisualBecause of inheritance and overriding issues with styling, the sizing style rules were not being correctly applied to the LastUpdatedCell. This was fixed by injecting Because LastUpdatedCell was duplicating ItemTableCell's border information, some borders were being doubled up. This was fixed with proper inheritance. OrganizationalDocumentation for ItemTableCell and LastUpdatedCell were not created. This was done now but docs should always be made at the same time as the component. Code formatting was inconsistent. This was fixed by using the jslint formatter from within VSCode. |
No description provided.